package com.xxx.common.web.controller;

import com.alibaba.cloud.nacos.registry.NacosRegistration;
import com.alibaba.cloud.nacos.registry.NacosServiceRegistry;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@AllArgsConstructor
public class WebController {

    private final NacosServiceRegistry nacosServiceRegistry;

    private final NacosRegistration nacosRegistration;

    @GetMapping("v2/healthCheck")
    public void healthCheck() {
        log.info("healthCheck ok!");
    }

    @GetMapping("v2/deregister")
    public void deregister() {
        nacosServiceRegistry.deregister(nacosRegistration);
        log.info("Service instance has been deregistered from nacos!");
    }

    @GetMapping("v2/register")
    public void register() {
        nacosServiceRegistry.register(nacosRegistration);
        log.info("Service instance has been register from nacos!");
    }
}
